//
//  YTFStatusModel.swift
//  sinaWeibo
//
//  Created by pro on 16/3/1.
//  Copyright © 2016年 pro. All rights reserved.
//

import UIKit

class YTFStatusModel: NSObject {
    /// 微博id
    var id: Int = 0
///  微博创建时间
    var created_at: String?
 /// 微博信息内容
    var text: String?
 /// 微博来源
    var source: String?
    
    //用户模型
    var user: YTFStatusUserModel?
    
    /// 转发数
    var reposts_count: Int = 0
    /// 评论数
    var comments_count: Int = 0
    /// 点赞数
    var attitudes_count: Int = 0
    
    /// retweeted_status object 被转发的微博信息字段，当该微博为转发微博的时候返回
    var retweeted_status: YTFStatusModel?
    
    //定义一个数组
    var pic_urls: [YTFPictureModel]?
    
    init(dict: [String:NSObject]) {
        
        super.init()
        
        //调用KVC
        setValuesForKeysWithDictionary(dict)
        
        if let userDict = dict["user"] as? [String:NSObject]{
            
            //获取到user的字典，然后进行字典转模型
            user = YTFStatusUserModel(dict: userDict)
        }
        
        if let repostDict = dict["retweeted_status"] as? [String: NSObject]{
            retweeted_status = YTFStatusModel(dict: repostDict)
        }
        
        //这是一个字典类型的数组
        if let pic_URLS = dict["pic_urls"] as? [[String: NSObject]]{
            //遍历字典转模型
            pic_urls = [YTFPictureModel]()
            
            for info in pic_URLS{
                
                pic_urls?.append(YTFPictureModel(dict: info))
            }
        }
        
    }
    
    //防止崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
}
